import 'package:first_flutter_project/main/anima/CanvasPointScroll3.dart';
import 'package:first_flutter_project/main/anima/PaintingContextLyerLearing.dart';
import 'package:first_flutter_project/main/anima/circle_beisaier_anima_learing.dart';
import 'package:first_flutter_project/main/anima/knowledge_domain_anima_learing.dart';
import 'package:first_flutter_project/main/anima/quad_tree_learing.dart';
import 'package:first_flutter_project/main/anima/quad_tree_learing2.dart';
import 'package:first_flutter_project/main/anima/text_anima_learing.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../Gesture/GestureDetectorConflictTest.dart';
import '../Gesture/GestureDetectorHitTest.dart';
import '../Gesture/NotificationInterruptTest.dart';
import 'BasicAnimatorUseing.dart';
import 'CanvasPointScroll.dart';
import 'CanvasPointScroll2.dart';
import 'MyCustomHeroAnimatorUseing.dart';
import 'MyMixAnimatorUseing.dart';
import 'RollingLotteryAnimator.dart';
import 'RollingLotteryAnimator2.dart';
import 'circle_beisaier_anima_learing_main.dart';
import 'draw_beisaier_anima_learing.dart';
import 'draw_path_learing.dart';
import 'load_status_widget.dart';
import 'load_status_widget1.dart';

class AnimatorLearing extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Material(
      child: SingleChildScrollView(
        child: Column(
          children: [
            TextButton(
              child: Text("基本的动画用法-缩放动画-MaterialPageRoute风格路由跳转动画"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return ScaleAnimationRoute();
                }));
              },
            ),
            TextButton(
              child: Text("基本的动画用法-缩放动画-FadeRoute自定义的风格路由跳转动画"),
              onPressed: () {
                var result = Navigator.push(
                    context,
                    FadeRoute(
                        builder: (context) {
                          return ScaleAnimationRoute();
                        },
                        barrierColor: Color(0xFF08CAE3),
                        barrierLabel: 'FadeRoutetgw'));
              },
            ),
            TextButton(
              child: Text("基本的动画用法-缩放动画-FadeTransition风格加上路由跳转动画"),
              onPressed: () {
                var result = Navigator.push(
                  context,
                  PageRouteBuilder(
                    transitionDuration: Duration(milliseconds: 500),
                    //动画时间为500毫秒
                    pageBuilder: (BuildContext context,
                        Animation<double> animation,
                        Animation secondaryAnimation) {
                      return FadeTransition(
                        //使用渐隐渐入过渡,
                        opacity: animation,
                        child: ScaleAnimationRoute(), //路由B
                      );
                    },
                  ),
                );
              },
            ),
            TextButton(
              child: Text("基本的动画用法-缩放动画，不过继承AnimatedWidget不需要手动实现更新"
                  "--ScaleAnimationRoute1缩放风格动画"),
              onPressed: () {
                var result = Navigator.push(context,
                    CupertinoPageRoute(builder: (context) {
                  return ScaleAnimationRoute1();
                }));
              },
            ),
            TextButton(
              child: Text("自定义缩放与位置移动动画实现 hero 效果"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return CustomHeroAnimation();
                }));
              },
            ),
            TextButton(
              child: Text("使用Hero控件，展示路由跳转功能"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return HeroAnimationRoute();
                }));
              },
            ),
            TextButton(
              child: Text("组合动画--柱状图动画"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return StaggerRoute();
                }));
              },
            ),
            TextButton(
              child: Text("组合动画--hero动画"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return StaggerRouteHero();
                }));
              },
            ),
            TextButton(
              child: Text("文本计时跳动动画"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return LoadingTextChangeWidget();
                }));
              },
            ),
            TextButton(
              child: Text("贝塞尔圆圈高度组件图"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return LoadingCircleChangeWidget(waveRatio: 0.6, index: 4);
                }));

                // var result = Navigator.push(context,
                //     MaterialPageRoute(builder: (context) {
                //       return LoadingCircleChangeMainWidget();
                //     }));
              },
            ),
            TextButton(
              child: Text("贝塞尔线条学习"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return DrawBeiSaierWidget();
                }));
              },
            ),
            TextButton(
              child: Text("组合动画--抽奖滚动动画"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return RollingLotteryAnimator();
                }));
              },
            ),
            TextButton(
              child: Text("组合动画--抽奖滚动动画stack"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return RollingLotteryStackAnimator();
                }));
              },
            ),
            TextButton(
              child: Text("画板"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return CanvasPointScroll();
                }));
              },
            ),
            TextButton(
              child: Text("画板2"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return CanvasPointScroll2();
                }));
              },
            ),
            TextButton(
              child: Text("画板listener3"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return CanvasPointScroll3();
                }));
              },
            ),
            TextButton(
              child: Text("小球加载动画,原始版build会导致画笔重构"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return LoadingIndicatorWidget2();
                }));
              },
            ),
            TextButton(
              child: Text("小球加载动画"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return LoadingIndicatorWidget();
                }));
              },
            ),
            TextButton(
              child: Text("PaintingContext--layer"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return PaintingContextLyerLearing();
                }));
              },
            ),
            TextButton(
              child: Text("知识图谱"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return KnowledgeDomainLearingWidget();
                }));
              },
            ),
            TextButton(
              child: Text("四叉树算法学习"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return QuadtreeLearningWidget();
                }));
              },
            ),
            TextButton(
              child: Text("四叉树算法学习2"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return QuadtreeLearningWidget2();
                }));
              },
            ),

            TextButton(
              child: Text("path 路径学习"),
              onPressed: () {
                var result = Navigator.push(context,
                    MaterialPageRoute(builder: (context) {
                  return DrawPathLearningWidget();
                }));
              },
            ),
          ],
        ),
      ),
    );
  }
}

///定义一个路由类
///虽然上面的两种方法都可以实现自定义切换动画，
///但实际使用时应优先考虑使用PageRouteBuilder，
///这样无需定义一个新的路由类，使用起来会比较方便。
///但是有些时候PageRouteBuilder是不能满足需求的，
///例如在应用过渡动画时我们需要读取当前路由的一些属性，
///这时就只能通过继承PageRoute的方式了，
///举个例子，假如我们只想在打开新路由时应用动画，而在返回时不使用动画，
///那么我们在构建过渡动画时就必须判断当前路由isActive属性是否为true，代码如下：
class FadeRoute extends PageRoute {
  FadeRoute({
    required this.builder,
    this.transitionDuration = const Duration(milliseconds: 300),
    this.opaque = true,
    this.barrierDismissible = false,
    required this.barrierColor,
    required this.barrierLabel,
    this.maintainState = true,
  });

  final WidgetBuilder builder;

  @override
  final Duration transitionDuration;

  @override
  final bool opaque;

  @override
  final bool barrierDismissible;

  @override
  final Color barrierColor;

  @override
  final String barrierLabel;

  @override
  final bool maintainState;

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
          Animation<double> secondaryAnimation) =>
      builder(context);

  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation, Widget child) {
    return FadeTransition(
      opacity: animation,
      child: builder(context),
    );
  }
}
